package paws.core.util

import paws.core._

object SimulationUtils {
  
  // This is to be used by classes that extend from Actor so that
  // processing may continue after the loop condition breaks instead
  // of immediate termination of the actor
  def doWhile(condition: => Boolean)(body: => Unit) {
    import scala.util.control.ControlThrowable
    if (condition) {
      try { body }
      catch {
        case _: ControlThrowable => ()
      }
      doWhile(condition)(body)
    }
  }
  
  // Calculate distance between two nodes
  def distance(a: Node, b: Node) = {
    val (ax, ay) = a.getLocation
    val (bx, by) = b.getLocation
    val dx = ax - bx
    val dy = ay - by
    Math.sqrt((dx * dx) + (dy * dy))
  }
}